//
//  StatusCellTopView.swift
//  01-界面搭建
//
//  Created by Apple on 15/11/8.
//  Copyright © 2015年 Apple. All rights reserved.
//

import UIKit
///顶部视图
class StatusCellTopView: UIView {
    /// 微博视图模型
    var viewModel:StatusViewModel? {
        didSet{
            // 姓名
            nameLabel.text = viewModel?.status.user?.screen_name
             // 头像
            iconView.sd_setImageWithURL(viewModel?.userProfileUrl, placeholderImage: UIImage(named:  "avatar_default_big"))
            // 会员图标
            memberIconView.image = viewModel?.userMemberImage
                 // 认证图标
            vipIconView.image = viewModel?.userVipImage
            // TODO - 后续会讲
            // 时间
            timeLabel.text =  viewModel?.status.created_at

            
        }
    }
    // MAKR: - 构造函数
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    // MARK: - 懒加载控件
    ///头像
    private lazy var iconView:UIImageView = UIImageView(ImageName: "avatar_default_big")
    /// 姓名
    private lazy var nameLabel:UILabel = UILabel(Labeltext: "战歌", Labelfont: 14)
    ///会员图标
    private lazy var memberIconView:UIImageView = UIImageView(ImageName:  "common_icon_membership_level1")
    /// 认证图标
    private lazy var vipIconView: UIImageView = UIImageView(ImageName: "avatar_vip")
    /// 时间标签
    private lazy var timeLabel: UILabel = UILabel(Labeltext: "现在", Textcolor: UIColor.orangeColor(), Labelfont: 11)
    /// 来源标签
    private lazy var sourceLabel: UILabel = UILabel(Labeltext: "来源",  Labelfont: 11)
}
// MARK: - 设置界面
extension StatusCellTopView {
    private func setupUI() {
        backgroundColor = UIColor(white: 0.95, alpha: 1.0)
        // 1. 添加控件
        addSubview(iconView)
        addSubview(nameLabel)
        addSubview(memberIconView)
        addSubview(vipIconView)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        // 2. 自动布局
        iconView.snp_makeConstraints { (make) -> Void in
            make.left.top.equalTo(self).offset(StatusCellMargin)
            make.width.height.equalTo(StatusCellIconWidth)
        }
        nameLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(iconView.snp_top)
            make.left.equalTo(iconView.snp_right).offset(StatusCellMargin)
        }
        memberIconView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(nameLabel.snp_top)
            make.left.equalTo(nameLabel.snp_right).offset(StatusCellMargin)
        }
        vipIconView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(iconView.snp_right)
            make.centerY.equalTo(iconView.snp_bottom)
        }
        timeLabel.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(iconView.snp_bottom)
            make.left.equalTo(iconView.snp_right).offset(StatusCellMargin)
        }
        sourceLabel.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(timeLabel.snp_bottom)
            make.left.equalTo(timeLabel.snp_right).offset(StatusCellMargin)
        }
    }
}